/* ====================================== toast  ====================================== */
import React from 'react'
// =====================================================================
const { $fn, $Lazy } = window
// ===================================================================== Component
const FormItem 	= $Lazy.load(()=>import('@antd/form/layout/item'))
const Select 	= $Lazy.load(()=>import('@antd/form/select'))
const Input 	= $Lazy.load(()=>import('@antd/form/input'))
//
const $cache = $Lazy.file(()=>import('#private/cache-api'))
// ===================================================================== 
class Index extends React.Component {
	state = {
		rulesData:[]
	}
	
	componentDidMount(){
		if(!this.props.data){
			$cache.then( async f => {
				if(!$fn.hasArray(this.state.rulesData)){
					const rulesData = await f.getDicCache({ code: 1300 })
					this.setState({ rulesData})
				}
			})
		}
	}
	
	render(){
		const { rulesData } = this.state
		let  { size = 'small', bordered, readOnly, clear, name, required, label, data, idStr, nameStr } = this.props
		idStr = data ? idStr : 'code'
		const props = { 
			size, 
			readOnly, 
			bordered, 
			clear
		}
		return (
			<div className='fx'>
				<FormItem width='50%' name={ name?.[0] } ml={10} mr={10} mb={10} rules={[ {required, message:'请选择转换规则'} ]}>
					<Select data={ data || rulesData} idStr={idStr} nameStr={nameStr} p='转换规则' {...props}/>
				</FormItem>
				<FormItem className='ex' name={ name?.[1] } mb={10} ml={10} rules={[ {required, message:`请输入${label}`} ]}>
					<Input name={ name?.[2] } p={label} {...props} mode='number' />
				</FormItem>
			</div>
		)
	}
}
export default Index